package com.zhiyou.controller;

import com.zhiyou.entity.Column;
import com.zhiyou.entity.PowerCenter;
import com.zhiyou.util.ColumnUtil;
import com.zhiyou.util.PWUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author sanshi
 * @desc
 * @create 2021-09-14 20:07
 */
@WebServlet("/DoChooice")
public class DoChooice extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //后台直接获取前端内容
        String powerName = req.getParameter("addPowerName");
        String powerAccountName = req.getParameter("addPowerAccountName");
        //通过授权处名得到column对象
        Column column = new ColumnUtil().getColumnByCname(powerName);
        //更新sys_user_chnl
        List<PowerCenter> pcList = new PWUtil().getAllPC3();
        String sql = "update sys_user_chnl set chnl_code=? where acct = ?";
        Object[] params = {column.getCid(),powerAccountName};
        int i = new PWUtil().updateInfo(sql, params);
        System.out.println(i);
        req.getSession().setAttribute("addPower","success");
        List<PowerCenter> pcList2 = new PWUtil().getAllPC3();
        req.getSession().setAttribute("pcList",pcList2);
        resp.sendRedirect("/page/AccountManagement.jsp");
    }
}
